package com.imooc.ecommerce.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhangshao
 * @Since: 2023/12/6 14:19
 */
@Slf4j
@Service
public class NacosClientService {

	@Autowired
	private DiscoveryClient discoveryClient;

	/**
	 * 打印 Nacos Client 信息到日志中
	 * @param serviceId
	 * @return
	 */
	public List<ServiceInstance> getNacosClientInfo(String serviceId){
		// useHystrixCommandAnnotation的超时是否发生熔断
		try{
			Thread.sleep(2000);
		}catch (InterruptedException ex){
		}
		log.info("request nacos client to get service instance info :[{}]",serviceId);
		return discoveryClient.getInstances(serviceId);
	}
}
